<#assign tit>会籍转让</#assign>
<@page.html title=tit>
<script type="text/javascript" src="${_appPath!}/js/cal.js"></script>
<script type="text/javascript">
  var _cinfo = null;
  function getcontr(c, t) {
    if(c!="") {
      getJson("getContract?code="+c+"&tp="+t, function(data){
        if(data.ret) {
          var mc = data.data;
          var fm = getEl("fm_input");
          fm.contractCode.value = mc.contractCode;
          fm.cardCode.value = mc.cardCode;
          fm.memberCode.value = mc.memberCode;
          fm.memberName.value = mc.memberName;
          fm.contractType.value = mc.cardType+" - "+mc.cardTypeName;
          fm.contractBegin.value = getDateStr(new Date(mc.beginTime));
          fm.contractEnd.value = getDateStr(new Date(mc.endTime));
          fm.contractAmount.value = formatMoney(mc.factPrice);
          fm.outAmount.value = formatMoney(mc.leftAmount);
          fm.addFee.value = formatMoney(mc.changeFee);
          fm.earnestId.value = "";
          fm.earnestAmount.value = "";
          _cinfo = mc;
          setc(null);
          setPayAmount();
        } else {
          window.alert(data.msg);
          clearData(t);
        }
      });
    }
  }

  function clearData(t) {
    var fm = getEl("fm_input");
    if(t!=1) fm.contractCode.value = "";
    if(t!=2) fm.cardCode.value = "";
    fm.memberCode.value = "";
    fm.memberName.value = "";
    fm.contractType.value = "";
    fm.contractBegin.value = "";
    fm.contractEnd.value = "";
    fm.contractAmount.value = "";
    fm.outAmount.value = "";
    fm.earnestId.value = "";
    fm.earnestAmount.value = "";
    fm.addFee.value = "";
    fm.payAmount.value = "";
    fm.note.value = "";
    _cinfo = null;
    setc(null);
  }

  function seldj() {
    var fm = getEl("fm_input");
    var url = "getEarnestList?type=4";
    if(fm.memberCode.value=="") {
      window.alert("请先输入合同编号");
      return;
    }
    url += "&memberCode="+fm.memberCode.value;
    openWin(url, 620, 400);
  }
  function seldjOk(vv) {
    var ss = vv.split(",");
    var fm = getEl("fm_input");
    fm.earnestId.value = ss[0];
    fm.earnestAmount.value = ss[1];
    setPayAmount();
  }

  function setPayAmount() {
    var fm = getEl("fm_input");
    if(fm.addFee.value=="") {
      fm.payAmount.value = "";
      return;
    }
    var m1 = parseFloat(fm.addFee.value);
    var m2 = 0;
    if(fm.earnestAmount.value!="") m2 = parseFloat(fm.earnestAmount.value);
    var m = m1-m2;
    if(m<0) m = 0;
    fm.payAmount.value = formatMoney(m);
  }


  function chgmtp(t) {
    document.getElementById("th_cdno").style.display = t==2?"":"none";
    document.getElementById("td_cdno").style.display = t==2?"":"none";
    document.getElementById("bt_sc").style.display = t==1?"":"none";
    var fm = getEl("fm_input");
    fm.chName.readOnly = t==2?true:false;
    fm.chName.className = t==2?"disable":"";
    fm.gender.readOnly = t==2?true:false;
    fm.gender.className = t==2?"disable":"";
    fm.idNumber.readOnly = t==2?true:false;
    fm.idNumber.className = t==2?"disable":"";
    fm.mobile.readOnly = t==2?true:false;
    fm.mobile.className = t==2?"disable":"";
    fm.gender.disabled = t==2?true:false;
    fm.idType.disabled = t==2?true:false;
    setc(null);
  }

  function chgcard(ipt) {
    var fm = getEl("fm_input");
    if(fm.newMemberType.value=="1")
      chkCard(ipt);
    else
      getminfo(ipt.value);
  }

  function getminfo(c) {
    if(c!="") {
      getJson("getMember?cardCode="+c, function(data){
        if(data.ret) {
          var mb = data.data;
          setc(mb);
        } else {
          window.alert(data.msg);
          setc(null);
        }
      });
    } else {
      setc(null);
    }
  }
  function setc(mb) {
    var fm = getEl("fm_input");
    if(mb) {
      fm.newCardCode.value = mb.card;
      fm.newMemberCode.value = mb.code;
      fm.chName.value = mb.name;
      fm.gender.value = mb.gender;
      fm.idType.value = mb.idType;
      fm.idNumber.value = mb.idNumber;
      fm.mobile.value = mb.mobile;
      getEl("td_mbp").innerHTML = '<input type="hidden" name="memberPhoto" value="'+mb.memberPhoto+'"><span onclick="showUpload(1);">'+(mb.memberPhoto?('<img src="${_picPath!}'+mb.memberPhoto+'" height="60">'):'<input type="button" class="opwin" value="照片"/>')+'</span>';
      getEl("td_mbidp").innerHTML = '<input type="hidden" name="idCardPhoto" value="'+mb.idCardPhoto+'"><span onclick="showUpload(2);">'+(mb.idCardPhoto?('<img src="${_appPath!}/images/idcard.png">'):'<input type="button" class="opwin" value="证件"/>')+'</span>';
    } else {
      fm.newCardCode.value = "";
      fm.newMemberCode.value = "";
      fm.chName.value = "";
      fm.gender.value = "";
      fm.idType.value = "";
      fm.idNumber.value = "";
      fm.mobile.value = "";
      getEl("td_mbp").innerHTML = '<input type="hidden" name="memberPhoto" value=""><span onclick="showUpload(1);"><input type="button" class="opwin" value="照片"/></span>';
      getEl("td_mbidp").innerHTML = '<input type="hidden" name="idCardPhoto" value=""><span onclick="showUpload(2);"><input type="button" class="opwin" value="证件"/></span>';
    }
  }


  function selCard() {
    openWin("getCardList", 500, 400);
  }
  function selCardOk(vv) {
    getEl("fm_input").newCardCode.value = vv;
  }
  function chkCard(ipt) {
    if(ipt.value!="") {
      getJson("getCardNew?cardCode="+ipt.value, function(data){
        if(data.ret) {
          ipt.value = data.data.cardCode;
        } else {
          window.alert(data.msg);
        }
      });
    }
  }

  function save(fm) {
    if(!fm) fm = getEl("fm_input");
    if(!_cinfo) {
      window.alert("请输入合同编号");
      return;
    }

    var mm = fm.payAmount.value;
    post(fm, function(){
      openWin("getPay?money="+mm, 500, 400);
      return false;
    });
    return false;
  }
  function payOk(vv) {
    var fm = getEl("fm_input");
    fm.payls.value = vv;
    postForm(fm.action, fm, saveRet);
  }
  function saveRet(data) {
    window.alert(data.msg);
    if(data.ret) {
      getEl("fm_input").reset();
      setc(null);
    } //window.location = "print?id="+data.data;
  }

  function showUpload(tp) {
    if(tp==2)
      openWin("../memberContract/upload?tp="+tp, 500, 400);
    else
      openWin("../memberContract/upload?tp="+tp, 650, 450);
  }
  function uploadOk(upl) {
    var td = getEl("td_mbp");
    td.childNodes[0].value = upl.furl;
    td.childNodes[1].innerHTML = '<img src="${_picPath!}'+upl.furl+'" height="60">';
  }
  function uploadOk2(upl) {
    var td = getEl("td_mbidp");
    td.childNodes[0].value = upl.furl;
    td.childNodes[1].innerHTML = '<img src="${_appPath!}/images/idcard.png">';
  }
</script>
<div style="width:600px;">

  <form id="fm_input" method="post" action="_add" onsubmit="return save(this);">
    <input type="hidden" name="payls" value="">
    <div class="kbox">
      <table class="input w4">
        <tr>
          <th width="85">合同编号</th>
          <td width="160"><input type="text" name="contractCode" value="" onchange="getcontr(this.value,1);" maxlength="20"></td>
          <th width="85">会员卡号</th>
          <td width="160"><input type="text" name="cardCode" value="" class="disable" readonly></td>
        </tr>
        <tbody style="border:3px solid #ffefce;">
          <tr>
            <th>会员姓名</th>
            <td><input type="text" name="memberName" value="" maxlength="10" class="disable" readonly></td>
            <th>会员编号</th>
            <td><input type="text" name="memberCode" value="" class="disable" readonly></td>
          </tr>
          <tr>
            <th>原会籍类型</th>
            <td colspan="3"><input type="text" name="contractType" value="" class="w2 disable" readonly></td>
          </tr>
          <tr>
            <th>合同起日</th>
            <td><input type="text" name="contractBegin" value="" class="date disable" maxlength="10" readonly></td>
            <th>合同迄日</th>
            <td><input type="text" name="contractEnd" value="" class="date disable" maxlength="10" readonly></td>
          </tr>
          <tr>
            <th>合同价值</th>
            <td><input type="text" name="contractAmount" value="" class="disable" readonly></td>
            <th>剩余价值</th>
            <td><input type="text" name="outAmount" value="" class="disable" readonly></td>
          </tr>
        </tbody>

        <tr>
          <th>定金编号</th>
          <td><input type="text" name="earnestId" value="" style="width:90px;" class="disable" readonly>
            <input type="button" class="opwin" value="..." onclick="seldj();"/></td>
          <th>定金金额</th>
          <td><input type="text" name="earnestAmount" value="" class="disable" readonly></td>
        </tr>

        <tr>
          <th>转入会员</th>
          <td><select name="newMemberType" onchange="chgmtp(this.value);">
            <option value="1">1-新会员</option>
            <option value="2">2-老会员</option>
          </select></td>
          <th id="th_cdno" style="display:none;">会员编号</th>
          <td id="td_cdno" style="display:none;"><input type="text" name="newMemberCode" value="" class="disable" readonly></td>
        </tr>
        <tr>
          <th>会员卡号</th>
          <td><input type="text" name="newCardCode" value="" onchange="chgcard(this);" maxlength="20" style="width:90px;" req="会员卡号">
            <input type="button" id="bt_sc" class="opwin" value="..." onclick="selCard();"/></td>
          <th>会员姓名</th>
          <td><input type="text" name="chName" value="" req="会员姓名"></td>
        </tr>
        <tr>
          <th>证件号</th>
          <td colspan="3"><select name="idType" req="证件类型"><#if idType??><#list idType as t><option value="${t.id}">${t.name}</option></#list></#if></select>
            <input type="text" name="idNumber" value="" req="证件号" onchange="chkid(this.value);" style="width:248px;"></td>
        </tr>
        <tr>
          <th>性别</th>
          <td><select name="gender"><#if gender??><#list gender as t><option value="${t.id}">${t.name}</option></#list></#if></select></td>
          <th>手机号码</th>
          <td><input type="text" name="mobile" value="" req="手机号码"></td>
        </tr>
        <tr>
          <th>照片</th>
          <td id="td_mbp"></td>
          <th>证件照</th>
          <td id="td_mbidp"></td>
        </tr>

        <tr>
          <th>手续费</th>
          <td><input type="text" name="addFee" value="" class="disable" readonly></td>
          <th>应收金额</th>
          <td><input type="text" name="payAmount" value="" class="disable" readonly req="应收金额"></td>
        </tr>
        <tr>
          <th>备注</th>
          <td colspan="3"><textarea name="note"></textarea></td>
        </tr>
      </table>
    </div>
    <div class="button"><input type="button" value="确认并提交" onclick="save();"></div>
  </form>
</div>

</@page.html>